gint width_chars;
gint max_width_chars;
+ gint lines;
};
/* Notes about the handling of links:
PROP_SINGLE_LINE_MODE,
PROP_ANGLE,
PROP_MAX_WIDTH_CHARS,
- PROP_TRACK_VISITED_LINKS
+ PROP_TRACK_VISITED_LINKS,
+ PROP_LINES
};
/* When rotating ellipsizable text we want the natural size to request
P_("Whether visited links should be tracked"),
TRUE,
GTK_PARAM_READWRITE));
+
+ /**
+ * GtkLabel:lines:
+ *
+ * The number of lines to which an ellipsized, wrapping label
+ * should be limited. This property has no effect if the
+ * label is not wrapping or ellipsized. Set this property to
+ * -1 if you don't want to limit the number of lines.
+ *
+ * Since: 3.10
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_LINES,
+ g_param_spec_int ("lines",
+ P_("Number of lines"),
+ P_("The desired number of lines, when ellipsizing a wrapping label"),
+ -1,
+ G_MAXINT,
+ -1,
+ GTK_PARAM_READWRITE));
/*
* Key bindings
*/
case PROP_TRACK_VISITED_LINKS:
gtk_label_set_track_visited_links (label, g_value_get_boolean (value));
break;
+ case PROP_LINES:
+ gtk_label_set_lines (label, g_value_get_int (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_TRACK_VISITED_LINKS:
g_value_set_boolean (value, gtk_label_get_track_visited_links (label));
break;
+ case PROP_LINES:
+ g_value_set_int (value, gtk_label_get_lines (label));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
pango_layout_set_ellipsize (priv->layout, priv->ellipsize);
pango_layout_set_wrap (priv->layout, priv->wrap_mode);
pango_layout_set_single_paragraph_mode (priv->layout, priv->single_line_mode);
+ if (priv->lines > 0)
+ pango_layout_set_height (priv->layout, - priv->lines);
gtk_label_update_layout_width (label);
}
return 0;
}
+
+/**
+ * gtk_label_set_lines:
+ * @label: a #GtkLabel
+ * @lines: the desired number of lines, or -1
+ *
+ * Sets the number of lines to which an ellipsized, wrapping label
+ * should be limited. This has no effect if the label is not wrapping
+ * or ellipsized. Set this to -1 if you don't want to limit the
+ * number of lines.
+ *
+ * Since: 3.10
+ */
+void
+gtk_label_set_lines (GtkLabel *label,
+ gint lines)
+{
+ GtkLabelPrivate *priv;
+
+ g_return_if_fail (GTK_IS_LABEL (label));
+
+ priv = label->priv;
+
+ if (priv->lines != lines)
+ {
+ priv->lines = lines;
+ g_object_notify (G_OBJECT (label), "lines");
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+ }
+}
+
+/**
+ * gtk_label_get_lines:
+ * @label: a #GtkLabel
+ *
+ * Gets the number of lines to which an ellipsized, wrapping
+ * label should be limited. See gtk_label_set_lines().
+ *
+ * Returns: The number of lines
+ *
+ * Since: 3.10
+ */
+gint
+gtk_label_get_lines (GtkLabel *label)
+{
+ g_return_if_fail (GTK_IS_LABEL (label));
+
+ return label->priv->lines;
+}